﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace b4
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Rectangle r = new Rectangle(2, 2.4);
            triangle t = new triangle(3, 4, 5);
            Square s = new Square(3);
            if (r.islegal())
                Console.WriteLine("长方形面积为：" + r.area());
            else
                Console.WriteLine("输入不合法");
            if (t.islegal())
                Console.WriteLine("三角形面积为：" + t.area());
            else
                Console.WriteLine("输入不合法");
            if (s.islegal())
                Console.WriteLine("正方形面积为：" + s.area());
            else
                Console.WriteLine("输入不合法");
        }
    }
    public abstract class Graph
    {
        public abstract double area();
        public abstract bool islegal();
    }
    public class triangle : Graph
    {
        public double side1;
        public double side2;
        public double side3;
        public triangle(double s1, double s2,double s3)
        {
            side1 = s1;
            side2 = s2;
            side3 = s3;
        }
        public override double area()
        {
            double p = side1 + side2 + side3;
            return Math.Sqrt(p * (p - side1) * (p - side2) * (p - side3));

        }
        public override bool islegal()
        {
            if (side1 + side2 < side3)
                return false;
            else if (side1 + side3 < side2)
                return false;
            else if (side2 + side3 < side1)
                return false;
            else return true;
            
        }
    }
    public  class Rectangle : Graph
    {
        public double length;
        public double width;
        public Rectangle(double l,double w)
        {
            length = l;
            width = w;
        }
        public override double area()
        {
            return length * width;
        }
        public override bool islegal()
        {
            return length > 0 && width > 0;
        }
    }
    public class Square : Rectangle
    {
        public Square(double w) : base(w, w)
        {
        }
    }

}



